package com.dennytech.tac.ui.adapter;

import java.util.List;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.GridView;

public class GridPagerAdapter extends PagerAdapter {

	private List<GridView> mGridViews;

	public GridPagerAdapter(List<GridView> list) {
		mGridViews = list;
	}

	public void setData(List<GridView> data) {
		mGridViews = data;
	}

	@Override
	public void destroyItem(View arg0, int arg1, Object arg2) {
		((ViewPager) arg0).removeView(mGridViews.get(arg1));
	}

	@Override
	public void finishUpdate(View arg0) {
	}

	@Override
	public int getCount() {
		return mGridViews.size();
	}

	@Override
	public Object instantiateItem(View arg0, int arg1) {
		((ViewPager) arg0).addView(mGridViews.get(arg1), 0);

		return mGridViews.get(arg1);
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == (arg1);
	}

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {
	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {
	}

	@Override
	public void notifyDataSetChanged() {
		for (GridView view : mGridViews) {
			((BaseAdapter) view.getAdapter()).notifyDataSetChanged();
		}
		super.notifyDataSetChanged();
	}
}
